﻿using UnityEngine;
using UnityEditor;

/// <summary>
/// UIBase的编辑器扩展
/// </summary>
[CustomEditor(typeof(UIPanelBase), true)]
public class UIInspectorExtension : Editor
{
    public override void OnInspectorGUI()
    {
        var ui = new SerializedObject(target);
        ui.Update();

        var propIterator = ui.GetIterator();
        propIterator.NextVisible(true);
        do
        {
            var prop = propIterator.Copy();
            switch (prop.name)
            {
                case "m_Script":
                    GUI.enabled = false;
                    EditorGUILayout.PropertyField(prop);
                    GUI.enabled = true;
                    break;

                case "animaWindow":
                case "animaDuration":
                    var showMode = ui.FindProperty("showAnimaMode");
                    if (showMode.enumValueIndex != (int)UIShowAnimaMode.Default)
                    {
                        EditorGUILayout.PropertyField(prop);
                    }
                    break;

                default:
                    EditorGUILayout.PropertyField(prop);
                    break;
            }
        } while (propIterator.NextVisible(false));

        ui.ApplyModifiedProperties();
    }
}